package com.zbkj.crmeb.store.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zbkj.crmeb.store.model.StoreOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zbkj.crmeb.store.model.StoreOrderInfo;
import com.zbkj.crmeb.store.model.StoreOrderInfoPicking;
import com.zbkj.crmeb.store.model.StoreOrderProduct;
import com.zbkj.crmeb.store.request.StoreOrderSearchRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author Mr.Zhang
 * @since 2020-05-28
 */
public interface StoreOrderDao extends BaseMapper<StoreOrder> {

    BigDecimal getTotalPrice(String where);

    BigDecimal getRefundPrice(String where);

    Integer getRefundTotal(String where);

    /**
     * 联合store_order_info表查询
     * @param request
     * @return
     */
    List<StoreOrder> selectListByUnionQuery(StoreOrderSearchRequest request);

    /**
     * 联合store_order_info表count
     * @param request
     * @return
     */
    Integer selectCountByCondition(StoreOrderSearchRequest request);


    BigDecimal selectSumPayPriceByCondition(StoreOrderSearchRequest request);

    List<StoreOrderProduct> getExportList(StoreOrderSearchRequest request);

    List<StoreOrderInfo> selectChildOrderListByUnionQuery(StoreOrderSearchRequest searchRequest);

    List<StoreOrderInfo> listOrderByQuery(StoreOrderSearchRequest searchRequest);

    List<StoreOrderInfo> listOrderInfoByUnique(StoreOrderSearchRequest searchRequest);

    List<StoreOrderInfo> selectChildCountByCondition(StoreOrderSearchRequest searchRequest);

    List<StoreOrderInfo> getSumAllPriceByCondition(StoreOrderSearchRequest searchRequest);

    List<StoreOrder> userAndOrderInfoList(@Param("ew")QueryWrapper<StoreOrder> queryWrapper);

    List<StoreOrder> getBacklogOrderQuantity();

    /**
     * 利润
     * @param searchRequest
     * @return
     */
    BigDecimal getProfitAmount(StoreOrderSearchRequest searchRequest);

    /**
     * 利润
     * @param searchRequest
     * @return
     */
    BigDecimal getSecondProfitAmount(StoreOrderSearchRequest searchRequest);

    int getRefundedPartCount(StoreOrderSearchRequest searchRequest);

    List<StoreOrderInfoPicking> selectVerifyOrderInfoList(StoreOrderSearchRequest request);

    @Select("select count(*) from (select * from eb_store_order ${ew.customSqlSegment}) a")
    Integer getPayOrderUserNum(@Param("ew") Wrapper wrapper);

}
